package com.donger.upms.biz.listener;

import com.donger.common.core.event.SysLogEvent;
import com.donger.upms.api.entity.SysLog;
import com.donger.upms.api.service.ISysLogService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 事件监听器
 *
 * @author xyx
 */
@AllArgsConstructor
@Slf4j
@Component
public class SysLogListener {

    private final ISysLogService sysLogService;

    @Async
    @Order
    @EventListener(SysLogEvent.class)
    public void saveSysLog(SysLogEvent event) {
        SysLog sysLog = (SysLog) event.getSource();
        sysLogService.save(sysLog);
    }
}
